package com.ryan.security.core.validate.code;

import com.ryan.security.core.properties.SecurityProperties;
import com.ryan.security.core.validate.code.sms.DefaultSmsSender;
import com.ryan.security.core.validate.code.sms.SmsCodeSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by kaimin on 2/1/2019.
 * time : 22:16
 */
//让验证码生成器可配置
@Configuration
public class ValidatorBeanConfig {

    @Autowired
    private SecurityProperties securityProperties;
    @Bean
    //如果容器中没找到这个imageCodeGenerator  bean ,才会初始化方法里面的逻辑
//    @ConditionalOnMissingBean(name = "imageCodeValidatorCodeGenerator")
    public ValidatorCodeGenerator imageCodeGenerator() {
        ImageCodeValidatorCodeGenerator imageCodeValidatorCodeGenerator = new ImageCodeValidatorCodeGenerator();
        imageCodeValidatorCodeGenerator.setSecurityProperties(securityProperties);
        return imageCodeValidatorCodeGenerator;
    }


    @Bean
//    @ConditionalOnMissingBean(name = "smsCodeSender")
    @ConditionalOnMissingBean(SmsCodeSender.class)
    public SmsCodeSender smsCodeGenerator() {

        return new DefaultSmsSender();
    }
}
